import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();//字符串个数
        String[] strings = new String[n];
        for (int i = 0; i < n; i++) {
            strings[i] = in.next();
        }
        getResult(strings);
    }

    public static void getResult(String[] strings){
        //需要用一个标识符来判断前一个操作是什么
        //0-没有操作 1-反转 2-添加一个字符
        for (int i = 0; i < strings.length; i++) {
            int flag = 0;
            StringBuilder result = new StringBuilder();//用来保存结果
            char[] chars = strings[i].toCharArray();
            for (int j = 0; j < chars.length; j++) {
                if(chars[j]=='R'){
                    //反转
                    result.reverse();
                    flag=1;
                    continue;
                } else if (chars[j]=='Z') {
                    //撤销上一步,只会出现一次
                    result = getReturn(flag,result);
                    continue;
                }
                result.append(chars[j]);
                flag=2;
            }
            System.out.println(result);//将当前处理字符串输出
        }
    }
    public static StringBuilder getReturn(int flag,StringBuilder str){
        if (flag==1) {
            //反转了
            return str.reverse();
        } else if (flag==2) {
            //添加了
            return str.deleteCharAt(str.length()-1);
        }
        return str;
    }
}
